package com.hsp_java.list_;

import java.util.*;

public class LinkedListCRUD {
    public static void main(String[] args) {
        LinkedList linkedList = new LinkedList();
        linkedList.add(1);
        linkedList.add(2);
        linkedList.add(3);

        linkedList.remove();
        //1.执行以下:

        /*
        public E remove() {
            return removeFirst();
        }
         */
        //2.删除第一个

        /*
        public E removeFirst() {
            final LinkedList.Node<E> f = first;
            if (f == null)
                throw new NoSuchElementException();
            return unlinkFirst(f);
        }

         */

        //3.执行 unlinkFirst,删除f指定的结点
        /*
        private E unlinkFirst(Node<E> f) {
            // assert f == first && f != null;
            final E element = f.item;
            final LinkedList.Node<E> next = f.next;
            f.item = null;
            f.next = null; // help GC
            first = next;
            if (next == null)
                last = null;
            else
                next.prev = null;
            size--;
            modCount++;
            return element;
         */


        System.out.println(linkedList);
        for (Object l : linkedList) {
            System.out.println(l);
        }
        Iterator iterator = linkedList.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next);
        }
        //1.构造器对应源码
        /*
        public LinkedList() {

        }
         */
        //2.此时linkedList属性 fist = null last = null size = 0 modCount = 0
        //3.执行
        /*
        public boolean add(E e) {
            linkLast(e);
            return true;
        }
         */
        //4.将新结点加入到双向链表最后
        /*
        void linkLast(E e) {
            final LinkedList.Node<E> l = last;
            final LinkedList.Node<E> newNode = new LinkedList.Node<>(l, e, null);
            last = newNode;
            if (l == null)
                first = newNode;
            else
                l.next = newNode;
            size++;
            modCount++;
        }
         */

    }
}
